#include <netinet/in.h>

#include <string>

#define LISTENQ 10
using namespace std;

int main(int argc, char *argv[])
{
	int listenfd, connfd;
	struct sockaddr_in servaddr;
	time_t ticks;
	char buff[2048];

	listenfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(10013);

	bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
	
	listen(listenfd, LISTENQ);

	while(1)
	{
		connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
		ticks = time(NULL);
		snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
		write(connfd, buff, strlen(buff));

		close(connfd);
	}

	return 0;
}

